package com.product;

import cn.hutool.extra.spring.SpringUtil;
import com.product.statemachine.common.DomainStateMachine;

import com.product.statemachine.common.DomainStateMachineFactory;
import com.product.statemachine.common.annotation.StateMachineInOperationAnnotation;
import com.product.statemachine.groupon.entity.GrouponEntity;
import com.product.statemachine.groupon.event.GrouponCancelEvent;
import com.product.statemachine.groupon.event.GrouponCompleteEvent;
import com.product.statemachine.groupon.event.GrouponJoinEvent;
import com.product.statemachine.groupon.event.GrouponOpenEvent;
import com.product.statemachine.order.entity.OrderEntity;
import com.product.statemachine.order.event.OrderPayEvent;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 */
@StateMachineInOperationAnnotation({"groupon","order"})
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
        DomainStateMachineFactory machineFactory = SpringUtil.getBean(DomainStateMachineFactory.class);
        DomainStateMachine grouponMachine = machineFactory.getDomainStateMachineBean("groupon");
        GrouponEntity grouponEntity = new GrouponEntity();
        OrderEntity orderEntity = new OrderEntity();
        grouponMachine.transition(grouponEntity, GrouponOpenEvent.class);
        grouponMachine.transition(grouponEntity, GrouponJoinEvent.class);
        grouponMachine.transition(grouponEntity, GrouponCompleteEvent.class);
        grouponMachine.transition(grouponEntity, GrouponCancelEvent.class);

        DomainStateMachine orderMachine = machineFactory.getDomainStateMachineBean("order");

        orderMachine.transition(orderEntity, OrderPayEvent.class);

    }
}
